package programer.interviewer;

import java.util.HashSet;
import java.util.Set;

public class Question5 {
    public boolean oneEditAway(String first, String second) {
        if(first.equals(second)) {
            return true;
        }
        
        if(first.length() < second.length()) 
            return oneEditAway(second, first);
        if(first.length() - second.length() >= 2) {
            return false;
        }
        int firstLen = first.length();
        int secondLen = second.length();
        int t = 0;
        if (firstLen - secondLen == 0) { //替换
            for(int i=0;i< first.length();i++) {
                if(first.charAt(i) != second.charAt(i)) {
                    t ++;
                }
            }
            return t<=1;
        } 
            
        int i=0,j=0;

        while(i < firstLen && j< secondLen) {
            if(first.charAt(i) == second.charAt(j)) {
                i++;
                j++;
            } else { 
                t++;
                i++;
            }
        }

        return t<=1;
               
    }


    public static void main(String[] args) {
        System.out.println(new Question5().oneEditAway("Mr", "Mr "));
    }
}
